//
//  TBProcessChainMC.h
//  TBShare
//
//  Created by JIENING ZHANG on 2020/2/25.
//  Copyright © 2020 taobao. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@class TBProcessNodeMC;

typedef NS_ENUM(NSInteger, TBProcessChainMCStatus){
    TBProcessChainMCStatusNotWork = 0,
    TBProcessChainMCStatusWorking,
    TBProcessChainMCStatusGoDie,
    TBProcessChainMCStatusGoSucc
};

typedef void(^TBProcessChainMCSuccBlock)(NSDictionary  * _Nullable succInfo);
typedef void(^TBProcessChainMCFailBlock)(NSDictionary * _Nullable failInfo);

NS_ASSUME_NONNULL_BEGIN

@interface TBProcessChainMC : NSObject

@property (nonatomic, assign, readonly) TBProcessChainMCStatus processStatus;

@property (nonatomic, strong) NSMutableDictionary       *processSharedInfo;
@property (nonatomic, copy, nullable) TBProcessChainMCSuccBlock   succBlock;
@property (nonatomic, copy, nullable) TBProcessChainMCFailBlock   failBlock;

// 仅仅调试用，
@property (nonatomic, assign) BOOL makeChainImageWhenEnd;

// succBlock failBlock 是否在主线程工作
@property (nonatomic, assign) BOOL blockRunInMainThread;


// 初始化为-1.f，如果>0, 表示开始处理后，如果超时，将godie
@property (nonatomic, assign) float timeOut4Process;

// 从 processNodeArray 第一个节点开始启动 处理链
-(void) start;
// 从 processNodeArray 某个节点开始启动 处理链
-(void) startWithNode:(TBProcessNodeMC *)startNode;

// 显示强制停止处理
-(void) stop:(BOOL)succ;
-(void) stop:(BOOL)succ info:(NSDictionary * _Nullable)info;

-(void) handleNodeGoDie:(TBProcessNodeMC *)processNode dieInfo:(NSDictionary * _Nullable)dieInfo;

-(void) handleNodeFinish:(TBProcessNodeMC *)processNode succInfo:(NSDictionary * _Nullable)succInfo;


// 向处理链添加两个节点，并且设置前后关联关系 preNode --(isStrong)--> subNode
-(void) addNodeIntoChain:(TBProcessNodeMC *)preNode subNode:(TBProcessNodeMC *)subNode isStrongRelation:(BOOL)isStrong;

// 向处理链添加preNode节点 和 subNodeList中所有节点，并且设置前后关联关系
//  preNode --(isStrong)--> subNode[0]
//  preNode --(isStrong)--> subNode[1]
//  ...
//  preNode --(isStrong)--> subNode[n-1]
-(void) addNodeIntoChain:(TBProcessNodeMC *)preNode subNodeList:(NSArray<TBProcessNodeMC *> *)subNodeList isStrongRelation:(BOOL)isStrong;

// 向处理链添加preNodeList中所有节点 和 subNode，并且设置前后关联关系
//  preNode[0] --(isStrong)--> subNode
//  preNode[1] --(isStrong)--> subNode
//  ...
//  preNode[n-1] --(isStrong)--> subNode
-(void) addNodeListIntoChain:(NSArray<TBProcessNodeMC *> *)preNodeList subNode:(TBProcessNodeMC *)subNode isStrongRelation:(BOOL)isStrong;

// 向处理链添加n个节点，并且设置前后关联关系 pNodes[0] --(isStrong)--> pNodes[1] --(isStrong)--> pNodes[2] ...  --(isStrong)--> pNodes[n-1]
-(void) addNodeSequeceIntoChain:(NSArray<TBProcessNodeMC *> *)pNodes isStrongRelation:(BOOL)isStrong;

// 设置关键节点，这些节点出错，正处理链中断处理
-(void) setKeyProcessNode:(NSArray<TBProcessNodeMC *> *)keyNodes;

// 设置结束节点，结束节点完成后，正处理链操作完成
-(void) setFinishNode:(TBProcessNodeMC *)finishNode;

-(void) setLogable:(BOOL)logable;
-(void) logNodeEvent:(id)info;
-(void) sort2PrintLog;
@end

NS_ASSUME_NONNULL_END
